import { defineStore } from 'pinia'
import {ref} from 'vue'
export const useCounterStore = defineStore('cart', () => {
    let carts=ref([])
    function addCart(){
        let username=localStorage.getItem('username')
    let usercarts=carts.value.filter(item=>item.username==username)
    let pdCart=carts.value.find(item=>item.username==username)
    if(pdCart){
       return carts.value++
    }
    else{
        carts.value.push({
            username:username,
            number:1,
            id:Math.floor(Math.random()*100000),
            checked:false
        })
    }
    }
    function delCart(){
        carts.value=carts.value.filter(item=>item.id!=id)
    }

  return { carts,addCart,delCart }
},
{
    persist: true,
  },
)